package cn.walls1717.juc.cas;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

/**
 * LongAdder相关api测试
 *
 * @author walls1717
 * @create 2022/12/12 19:57
 **/
@Slf4j
public class LongAdderApiDemo {

    public static void main(String[] args) {
        LongAdder longAdder = new LongAdder();
        longAdder.increment();
        longAdder.increment();
        longAdder.increment();
        log.info(longAdder.sum() + "");

        LongAccumulator longAccumulator = new LongAccumulator((x,y)->x+y, 0);
        longAccumulator.accumulate(1);
        longAccumulator.accumulate(3);
        log.info(longAccumulator.get() + "");
    }
}
